package ca.uwindsor.cs.deepweb.utility.documentanalysis;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class TermsExtractorbyFrequencyRange {
	
	protected int startingfrequency;
	
	protected int endingfrequency;
	
	/**
	 * constructor
	 * @param startingfrequency 
	 * @param endingfrequency 
	 */
	public TermsExtractorbyFrequencyRange(int startingfrequency, int endingfrequency) {
		this.startingfrequency = startingfrequency;
		this.endingfrequency = endingfrequency;
	}

	public void load(String file) {
		InputStreamReader reader = null;
		BufferedReader bufferedreader_in;
		String string_line = new String();
		String[] temp;
		try {
			reader = new InputStreamReader(new FileInputStream(file));
			bufferedreader_in = new BufferedReader(reader);
			string_line = bufferedreader_in.readLine();
			int f;
			while (string_line != null) {
				if (!string_line.equals("")) {
					temp = string_line.split("\t");
					f= Integer.parseInt(temp[1]);
					if(f>=startingfrequency && f<=endingfrequency){
						System.out.println(temp[0]);
					}
					// list.add(cell);
				}
				string_line = bufferedreader_in.readLine();
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		args = new String[3];
//		args[0]="/var/research/estimation/experiment/documentanalysis/corrected/gov2_0_terms_of_digits_5digit_with_ocurrence_sorted.txt";
//		args[1]="1";
//		args[2]="13";
		if(args.length!=3){
			System.exit(-1);
		}
		TermsExtractorbyFrequencyRange e = new TermsExtractorbyFrequencyRange(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
		e.load(args[0]);

	}

}
